<?php
	/**
	 * This is a MetaControl class, providing a QForm or QPanel access to event handlers
	 * and QControls to perform the Create, Edit, and Delete functionality
	 * of the Borrowdetails class.  This code-generated class
	 * contains all the basic elements to help a QPanel or QForm display an HTML form that can
	 * manipulate a single Borrowdetails object.
	 *
	 * To take advantage of some (or all) of these control objects, you
	 * must create a new QForm or QPanel which instantiates a BorrowdetailsMetaControl
	 * class.
	 *
	 * Any and all changes to this file will be overwritten with any subsequent
	 * code re-generation.
	 * 
	 * @package My Application
	 * @subpackage MetaControls
	 * property-read Borrowdetails $Borrowdetails the actual Borrowdetails data class being edited
	 * property QLabel $IdControl
	 * property-read QLabel $IdLabel
	 * property QTextBox $AsinControl
	 * property-read QLabel $AsinLabel
	 * property QIntegerTextBox $BorrowedByControl
	 * property-read QLabel $BorrowedByLabel
	 * property QDateTimePicker $BorrowDateControl
	 * property-read QLabel $BorrowDateLabel
	 * property QDateTimePicker $ReturnDateControl
	 * property-read QLabel $ReturnDateLabel
	 * property QDateTimePicker $ExpectedReturnControl
	 * property-read QLabel $ExpectedReturnLabel
	 * property QIntegerTextBox $BorrowedFromControl
	 * property-read QLabel $BorrowedFromLabel
	 * property-read string $TitleVerb a verb indicating whether or not this is being edited or created
	 * property-read boolean $EditMode a boolean indicating whether or not this is being edited or created
	 */

	class BorrowdetailsMetaControlGen extends QBaseClass {
		// General Variables
		protected $objBorrowdetails;
		protected $objParentObject;
		protected $strTitleVerb;
		protected $blnEditMode;

		// Controls that allow the editing of Borrowdetails's individual data fields
		protected $lblId;
		protected $txtAsin;
		protected $txtBorrowedBy;
		protected $calBorrowDate;
		protected $calReturnDate;
		protected $calExpectedReturn;
		protected $txtBorrowedFrom;

		// Controls that allow the viewing of Borrowdetails's individual data fields
		protected $lblAsin;
		protected $lblBorrowedBy;
		protected $lblBorrowDate;
		protected $lblReturnDate;
		protected $lblExpectedReturn;
		protected $lblBorrowedFrom;

		// QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References

		// QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References


		/**
		 * Main constructor.  Constructor OR static create methods are designed to be called in either
		 * a parent QPanel or the main QForm when wanting to create a
		 * BorrowdetailsMetaControl to edit a single Borrowdetails object within the
		 * QPanel or QForm.
		 *
		 * This constructor takes in a single Borrowdetails object, while any of the static
		 * create methods below can be used to construct based off of individual PK ID(s).
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this BorrowdetailsMetaControl
		 * @param Borrowdetails $objBorrowdetails new or existing Borrowdetails object
		 */
		 public function __construct($objParentObject, Borrowdetails $objBorrowdetails) {
			// Setup Parent Object (e.g. QForm or QPanel which will be using this BorrowdetailsMetaControl)
			$this->objParentObject = $objParentObject;

			// Setup linked Borrowdetails object
			$this->objBorrowdetails = $objBorrowdetails;

			// Figure out if we're Editing or Creating New
			if ($this->objBorrowdetails->__Restored) {
				$this->strTitleVerb = QApplication::Translate('Edit');
				$this->blnEditMode = true;
			} else {
				$this->strTitleVerb = QApplication::Translate('Create');
				$this->blnEditMode = false;
			}
		 }

		/**
		 * Static Helper Method to Create using PK arguments
		 * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
		 * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
		 * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to 
		 * edit, or if we are also allowed to create a new one, etc.
		 * 
		 * @param mixed $objParentObject QForm or QPanel which will be using this BorrowdetailsMetaControl
		 * @param integer $intId primary key value
		 * @param QMetaControlCreateType $intCreateType rules governing Borrowdetails object creation - defaults to CreateOrEdit
 		 * @return BorrowdetailsMetaControl
		 */
		public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			// Attempt to Load from PK Arguments
			if (strlen($intId)) {
				$objBorrowdetails = Borrowdetails::Load($intId);

				// Borrowdetails was found -- return it!
				if ($objBorrowdetails)
					return new BorrowdetailsMetaControl($objParentObject, $objBorrowdetails);

				// If CreateOnRecordNotFound not specified, throw an exception
				else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
					throw new QCallerException('Could not find a Borrowdetails object with PK arguments: ' . $intId);

			// If EditOnly is specified, throw an exception
			} else if ($intCreateType == QMetaControlCreateType::EditOnly)
				throw new QCallerException('No PK arguments specified');

			// If we are here, then we need to create a new record
			return new BorrowdetailsMetaControl($objParentObject, new Borrowdetails());
		}

		/**
		 * Static Helper Method to Create using PathInfo arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this BorrowdetailsMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing Borrowdetails object creation - defaults to CreateOrEdit
		 * @return BorrowdetailsMetaControl
		 */
		public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::PathInfo(0);
			return BorrowdetailsMetaControl::Create($objParentObject, $intId, $intCreateType);
		}

		/**
		 * Static Helper Method to Create using QueryString arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this BorrowdetailsMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing Borrowdetails object creation - defaults to CreateOrEdit
		 * @return BorrowdetailsMetaControl
		 */
		public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::QueryString('intId');
			return BorrowdetailsMetaControl::Create($objParentObject, $intId, $intCreateType);
		}



		///////////////////////////////////////////////
		// PUBLIC CREATE and REFRESH METHODS
		///////////////////////////////////////////////

		/**
		 * Create and setup QLabel lblId
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblId_Create($strControlId = null) {
			$this->lblId = new QLabel($this->objParentObject, $strControlId);
			$this->lblId->Name = QApplication::Translate('Id');
			if ($this->blnEditMode)
				$this->lblId->Text = $this->objBorrowdetails->Id;
			else
				$this->lblId->Text = 'N/A';
			return $this->lblId;
		}

		/**
		 * Create and setup QTextBox txtAsin
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtAsin_Create($strControlId = null) {
			$this->txtAsin = new QTextBox($this->objParentObject, $strControlId);
			$this->txtAsin->Name = QApplication::Translate('Asin');
			$this->txtAsin->Text = $this->objBorrowdetails->Asin;
			$this->txtAsin->Required = true;
			$this->txtAsin->MaxLength = Borrowdetails::AsinMaxLength;
			return $this->txtAsin;
		}

		/**
		 * Create and setup QLabel lblAsin
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblAsin_Create($strControlId = null) {
			$this->lblAsin = new QLabel($this->objParentObject, $strControlId);
			$this->lblAsin->Name = QApplication::Translate('Asin');
			$this->lblAsin->Text = $this->objBorrowdetails->Asin;
			$this->lblAsin->Required = true;
			return $this->lblAsin;
		}

		/**
		 * Create and setup QIntegerTextBox txtBorrowedBy
		 * @param string $strControlId optional ControlId to use
		 * @return QIntegerTextBox
		 */
		public function txtBorrowedBy_Create($strControlId = null) {
			$this->txtBorrowedBy = new QIntegerTextBox($this->objParentObject, $strControlId);
			$this->txtBorrowedBy->Name = QApplication::Translate('Borrowed By');
			$this->txtBorrowedBy->Text = $this->objBorrowdetails->BorrowedBy;
			return $this->txtBorrowedBy;
		}

		/**
		 * Create and setup QLabel lblBorrowedBy
		 * @param string $strControlId optional ControlId to use
		 * @param string $strFormat optional sprintf format to use
		 * @return QLabel
		 */
		public function lblBorrowedBy_Create($strControlId = null, $strFormat = null) {
			$this->lblBorrowedBy = new QLabel($this->objParentObject, $strControlId);
			$this->lblBorrowedBy->Name = QApplication::Translate('Borrowed By');
			$this->lblBorrowedBy->Text = $this->objBorrowdetails->BorrowedBy;
			$this->lblBorrowedBy->Format = $strFormat;
			return $this->lblBorrowedBy;
		}

		/**
		 * Create and setup QDateTimePicker calBorrowDate
		 * @param string $strControlId optional ControlId to use
		 * @return QDateTimePicker
		 */
		public function calBorrowDate_Create($strControlId = null) {
			$this->calBorrowDate = new QDateTimePicker($this->objParentObject, $strControlId);
			$this->calBorrowDate->Name = QApplication::Translate('Borrow Date');
			$this->calBorrowDate->DateTime = $this->objBorrowdetails->BorrowDate;
			$this->calBorrowDate->DateTimePickerType = QDateTimePickerType::Date;
			$this->calBorrowDate->Required = true;
			return $this->calBorrowDate;
		}

		/**
		 * Create and setup QLabel lblBorrowDate
		 * @param string $strControlId optional ControlId to use
		 * @param string $strDateTimeFormat optional DateTimeFormat to use
		 * @return QLabel
		 */
		public function lblBorrowDate_Create($strControlId = null, $strDateTimeFormat = null) {
			$this->lblBorrowDate = new QLabel($this->objParentObject, $strControlId);
			$this->lblBorrowDate->Name = QApplication::Translate('Borrow Date');
			$this->strBorrowDateDateTimeFormat = $strDateTimeFormat;
			$this->lblBorrowDate->Text = sprintf($this->objBorrowdetails->BorrowDate) ? $this->objBorrowdetails->BorrowDate->__toString($this->strBorrowDateDateTimeFormat) : null;
			$this->lblBorrowDate->Required = true;
			return $this->lblBorrowDate;
		}

		protected $strBorrowDateDateTimeFormat;


		/**
		 * Create and setup QDateTimePicker calReturnDate
		 * @param string $strControlId optional ControlId to use
		 * @return QDateTimePicker
		 */
		public function calReturnDate_Create($strControlId = null) {
			$this->calReturnDate = new QDateTimePicker($this->objParentObject, $strControlId);
			$this->calReturnDate->Name = QApplication::Translate('Return Date');
			$this->calReturnDate->DateTime = $this->objBorrowdetails->ReturnDate;
			$this->calReturnDate->DateTimePickerType = QDateTimePickerType::Date;
			return $this->calReturnDate;
		}

		/**
		 * Create and setup QLabel lblReturnDate
		 * @param string $strControlId optional ControlId to use
		 * @param string $strDateTimeFormat optional DateTimeFormat to use
		 * @return QLabel
		 */
		public function lblReturnDate_Create($strControlId = null, $strDateTimeFormat = null) {
			$this->lblReturnDate = new QLabel($this->objParentObject, $strControlId);
			$this->lblReturnDate->Name = QApplication::Translate('Return Date');
			$this->strReturnDateDateTimeFormat = $strDateTimeFormat;
			$this->lblReturnDate->Text = sprintf($this->objBorrowdetails->ReturnDate) ? $this->objBorrowdetails->ReturnDate->__toString($this->strReturnDateDateTimeFormat) : null;
			return $this->lblReturnDate;
		}

		protected $strReturnDateDateTimeFormat;


		/**
		 * Create and setup QDateTimePicker calExpectedReturn
		 * @param string $strControlId optional ControlId to use
		 * @return QDateTimePicker
		 */
		public function calExpectedReturn_Create($strControlId = null) {
			$this->calExpectedReturn = new QDateTimePicker($this->objParentObject, $strControlId);
			$this->calExpectedReturn->Name = QApplication::Translate('Expected Return');
			$this->calExpectedReturn->DateTime = $this->objBorrowdetails->ExpectedReturn;
			$this->calExpectedReturn->DateTimePickerType = QDateTimePickerType::Date;
			$this->calExpectedReturn->Required = true;
			return $this->calExpectedReturn;
		}

		/**
		 * Create and setup QLabel lblExpectedReturn
		 * @param string $strControlId optional ControlId to use
		 * @param string $strDateTimeFormat optional DateTimeFormat to use
		 * @return QLabel
		 */
		public function lblExpectedReturn_Create($strControlId = null, $strDateTimeFormat = null) {
			$this->lblExpectedReturn = new QLabel($this->objParentObject, $strControlId);
			$this->lblExpectedReturn->Name = QApplication::Translate('Expected Return');
			$this->strExpectedReturnDateTimeFormat = $strDateTimeFormat;
			$this->lblExpectedReturn->Text = sprintf($this->objBorrowdetails->ExpectedReturn) ? $this->objBorrowdetails->ExpectedReturn->__toString($this->strExpectedReturnDateTimeFormat) : null;
			$this->lblExpectedReturn->Required = true;
			return $this->lblExpectedReturn;
		}

		protected $strExpectedReturnDateTimeFormat;


		/**
		 * Create and setup QIntegerTextBox txtBorrowedFrom
		 * @param string $strControlId optional ControlId to use
		 * @return QIntegerTextBox
		 */
		public function txtBorrowedFrom_Create($strControlId = null) {
			$this->txtBorrowedFrom = new QIntegerTextBox($this->objParentObject, $strControlId);
			$this->txtBorrowedFrom->Name = QApplication::Translate('Borrowed From');
			$this->txtBorrowedFrom->Text = $this->objBorrowdetails->BorrowedFrom;
			return $this->txtBorrowedFrom;
		}

		/**
		 * Create and setup QLabel lblBorrowedFrom
		 * @param string $strControlId optional ControlId to use
		 * @param string $strFormat optional sprintf format to use
		 * @return QLabel
		 */
		public function lblBorrowedFrom_Create($strControlId = null, $strFormat = null) {
			$this->lblBorrowedFrom = new QLabel($this->objParentObject, $strControlId);
			$this->lblBorrowedFrom->Name = QApplication::Translate('Borrowed From');
			$this->lblBorrowedFrom->Text = $this->objBorrowdetails->BorrowedFrom;
			$this->lblBorrowedFrom->Format = $strFormat;
			return $this->lblBorrowedFrom;
		}



		/**
		 * Refresh this MetaControl with Data from the local Borrowdetails object.
		 * @param boolean $blnReload reload Borrowdetails from the database
		 * @return void
		 */
		public function Refresh($blnReload = false) {
			if ($blnReload)
				$this->objBorrowdetails->Reload();

			if ($this->lblId) if ($this->blnEditMode) $this->lblId->Text = $this->objBorrowdetails->Id;

			if ($this->txtAsin) $this->txtAsin->Text = $this->objBorrowdetails->Asin;
			if ($this->lblAsin) $this->lblAsin->Text = $this->objBorrowdetails->Asin;

			if ($this->txtBorrowedBy) $this->txtBorrowedBy->Text = $this->objBorrowdetails->BorrowedBy;
			if ($this->lblBorrowedBy) $this->lblBorrowedBy->Text = $this->objBorrowdetails->BorrowedBy;

			if ($this->calBorrowDate) $this->calBorrowDate->DateTime = $this->objBorrowdetails->BorrowDate;
			if ($this->lblBorrowDate) $this->lblBorrowDate->Text = sprintf($this->objBorrowdetails->BorrowDate) ? $this->objBorrowdetails->__toString($this->strBorrowDateDateTimeFormat) : null;

			if ($this->calReturnDate) $this->calReturnDate->DateTime = $this->objBorrowdetails->ReturnDate;
			if ($this->lblReturnDate) $this->lblReturnDate->Text = sprintf($this->objBorrowdetails->ReturnDate) ? $this->objBorrowdetails->__toString($this->strReturnDateDateTimeFormat) : null;

			if ($this->calExpectedReturn) $this->calExpectedReturn->DateTime = $this->objBorrowdetails->ExpectedReturn;
			if ($this->lblExpectedReturn) $this->lblExpectedReturn->Text = sprintf($this->objBorrowdetails->ExpectedReturn) ? $this->objBorrowdetails->__toString($this->strExpectedReturnDateTimeFormat) : null;

			if ($this->txtBorrowedFrom) $this->txtBorrowedFrom->Text = $this->objBorrowdetails->BorrowedFrom;
			if ($this->lblBorrowedFrom) $this->lblBorrowedFrom->Text = $this->objBorrowdetails->BorrowedFrom;

		}



		///////////////////////////////////////////////
		// PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
		///////////////////////////////////////////////





		///////////////////////////////////////////////
		// PUBLIC BORROWDETAILS OBJECT MANIPULATORS
		///////////////////////////////////////////////

		/**
		 * This will save this object's Borrowdetails instance,
		 * updating only the fields which have had a control created for it.
		 */
		public function SaveBorrowdetails() {
			try {
				// Update any fields for controls that have been created
				if ($this->txtAsin) $this->objBorrowdetails->Asin = $this->txtAsin->Text;
				if ($this->txtBorrowedBy) $this->objBorrowdetails->BorrowedBy = $this->txtBorrowedBy->Text;
				if ($this->calBorrowDate) $this->objBorrowdetails->BorrowDate = $this->calBorrowDate->DateTime;
				if ($this->calReturnDate) $this->objBorrowdetails->ReturnDate = $this->calReturnDate->DateTime;
				if ($this->calExpectedReturn) $this->objBorrowdetails->ExpectedReturn = $this->calExpectedReturn->DateTime;
				if ($this->txtBorrowedFrom) $this->objBorrowdetails->BorrowedFrom = $this->txtBorrowedFrom->Text;

				// Update any UniqueReverseReferences (if any) for controls that have been created for it

				// Save the Borrowdetails object
				$this->objBorrowdetails->Save();

				// Finally, update any ManyToManyReferences (if any)
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * This will DELETE this object's Borrowdetails instance from the database.
		 * It will also unassociate itself from any ManyToManyReferences.
		 */
		public function DeleteBorrowdetails() {
			$this->objBorrowdetails->Delete();
		}		



		///////////////////////////////////////////////
		// PUBLIC GETTERS and SETTERS
		///////////////////////////////////////////////

		/**
		 * Override method to perform a property "Get"
		 * This will get the value of $strName
		 *
		 * @param string $strName Name of the property to get
		 * @return mixed
		 */
		public function __get($strName) {
			switch ($strName) {
				// General MetaControlVariables
				case 'Borrowdetails': return $this->objBorrowdetails;
				case 'TitleVerb': return $this->strTitleVerb;
				case 'EditMode': return $this->blnEditMode;

				// Controls that point to Borrowdetails fields -- will be created dynamically if not yet created
				case 'IdControl':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'IdLabel':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'AsinControl':
					if (!$this->txtAsin) return $this->txtAsin_Create();
					return $this->txtAsin;
				case 'AsinLabel':
					if (!$this->lblAsin) return $this->lblAsin_Create();
					return $this->lblAsin;
				case 'BorrowedByControl':
					if (!$this->txtBorrowedBy) return $this->txtBorrowedBy_Create();
					return $this->txtBorrowedBy;
				case 'BorrowedByLabel':
					if (!$this->lblBorrowedBy) return $this->lblBorrowedBy_Create();
					return $this->lblBorrowedBy;
				case 'BorrowDateControl':
					if (!$this->calBorrowDate) return $this->calBorrowDate_Create();
					return $this->calBorrowDate;
				case 'BorrowDateLabel':
					if (!$this->lblBorrowDate) return $this->lblBorrowDate_Create();
					return $this->lblBorrowDate;
				case 'ReturnDateControl':
					if (!$this->calReturnDate) return $this->calReturnDate_Create();
					return $this->calReturnDate;
				case 'ReturnDateLabel':
					if (!$this->lblReturnDate) return $this->lblReturnDate_Create();
					return $this->lblReturnDate;
				case 'ExpectedReturnControl':
					if (!$this->calExpectedReturn) return $this->calExpectedReturn_Create();
					return $this->calExpectedReturn;
				case 'ExpectedReturnLabel':
					if (!$this->lblExpectedReturn) return $this->lblExpectedReturn_Create();
					return $this->lblExpectedReturn;
				case 'BorrowedFromControl':
					if (!$this->txtBorrowedFrom) return $this->txtBorrowedFrom_Create();
					return $this->txtBorrowedFrom;
				case 'BorrowedFromLabel':
					if (!$this->lblBorrowedFrom) return $this->lblBorrowedFrom_Create();
					return $this->lblBorrowedFrom;
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		/**
		 * Override method to perform a property "Set"
		 * This will set the property $strName to be $mixValue
		 *
		 * @param string $strName Name of the property to set
		 * @param string $mixValue New value of the property
		 * @return mixed
		 */
		public function __set($strName, $mixValue) {
			try {
				switch ($strName) {
					// Controls that point to Borrowdetails fields
					case 'IdControl':
						return ($this->lblId = QType::Cast($mixValue, 'QControl'));
					case 'AsinControl':
						return ($this->txtAsin = QType::Cast($mixValue, 'QControl'));
					case 'BorrowedByControl':
						return ($this->txtBorrowedBy = QType::Cast($mixValue, 'QControl'));
					case 'BorrowDateControl':
						return ($this->calBorrowDate = QType::Cast($mixValue, 'QControl'));
					case 'ReturnDateControl':
						return ($this->calReturnDate = QType::Cast($mixValue, 'QControl'));
					case 'ExpectedReturnControl':
						return ($this->calExpectedReturn = QType::Cast($mixValue, 'QControl'));
					case 'BorrowedFromControl':
						return ($this->txtBorrowedFrom = QType::Cast($mixValue, 'QControl'));
					default:
						return parent::__set($strName, $mixValue);
				}
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}
	}
?>